﻿#ifndef PST_POLARGRAPH_H
#define PST_POLARGRAPH_H

#include "qcustomplot.h"
#include <QList>

namespace pst
{
    class LineChartTracer;

    class PolarGraph : public QCPPolarGraph
    {
        Q_OBJECT
    public:
        PolarGraph(QCPPolarAxisAngular* keyAxis, QCPPolarAxisRadial* valueAxis);
        ~PolarGraph() override;

        void setSelectedPen(const QPen& pen);
        void setNormalPen(const QPen& pen);
        QCPAbstractLegendItem* getLegendItem() const;

        QPen getSelectedPen() const;
        QPen getNormalPen() const;
        bool isSelected() const;

        // wont emit signal
        void setSelected(bool selected);

        void addTracer(LineChartTracer* tracer);
        void removeTracer(LineChartTracer* tracer);
        QList<LineChartTracer*> getAllTracer();
        void removeAllTracer();

        void setVisible(bool on);

    Q_SIGNALS:
        void signal_selectionChanged(bool selected);
        void signal_legendItemSelectionChanged(bool selected);
        void signal_mouseDoubleClicked(QMouseEvent* event, const QVariant& details);

    protected Q_SLOTS:
        // will emit signal
        void slot_setSelected(bool select);

    protected:
        // 更新选中状态
        void updateSelectionState(bool selected);

        void mouseDoubleClickEvent(QMouseEvent* event, const QVariant& details) override;

    protected:
        QPen m_selectedPen;
        QPen m_normalPen;
        volatile bool m_isSelected{false};
        QCPAbstractLegendItem* m_legendItem{ nullptr };
        QList<LineChartTracer*> m_tracerList;

    private:
        Q_DISABLE_COPY(PolarGraph)
        friend class QCPPolarLegendItem;
    };
}

#endif // PST_POLARGRAPH_H
